﻿namespace Harness
{
    using System;

    internal class CommandFactory
    {
        #region Fields

        private static readonly FlyweightFactory<ICommand> Flyweight = new FlyweightFactory<ICommand>("Harness.Commands", "Command");

        #endregion

        #region Public Methods

        public static ICommand GetCommand(string cmd)
        {
            if (string.IsNullOrWhiteSpace(cmd))
            {
                throw new ArgumentOutOfRangeException("cmd");
            }

            if (!Flyweight.Exists(cmd))
            {
                string msg = string.Format(
                    Properties.Resources.Exception_CommandNotFound,
                    cmd);

                throw new InvalidOperationException(msg);
            }

            return Flyweight.Get(cmd);
        }

        #endregion
    }
}
